use std::future::Future;
use std::pin::Pin;
// 定义一个异步函数类型：接收T参数，返回 Future<Output = T>
//需要返回T,则在Output=T,如不需要，则是Output=()
type AsyncFn<T> = dyn Fn(T) -> Pin<Box<dyn Future<Output = ()> + Send>> + Send;
pub struct AsyncCallFunc<T> {
    call_func:Box<AsyncFn<T>>,
}
impl<T> AsyncCallFunc<T> {
    //Box::new(|x| Box::pin(add_one(x)))
    pub fn register(call:Box<AsyncFn<T>>) ->Self{
        AsyncCallFunc {
            call_func:call,
        }
    }
    //需要返回T，则在函数末添加->T
    async fn call_async_fn(func: &AsyncFn<T>, arg: T) {
        func(arg).await
    }
    pub async fn active(&self,value:T){
        Self::call_async_fn(&*self.call_func, value).await;
    }
}

